/**
 * 
 */
package ru.amse.stroganova.ui.command;

import ru.amse.stroganova.presentation.EdgePresentation;
import ru.amse.stroganova.presentation.GraphPresentation;
import ru.amse.stroganova.presentation.VertexPresentation;
import ru.amse.stroganova.ui.visual.GraphElementSelection;

class AddEdgeCommand implements Command {

	private final GraphPresentation graphPresentation;
	
	private final GraphElementSelection graphSelection;
	
	private final EdgePresentation edge;
	
	/**
	 * Creates new AddEdgeCommand.
	 * 
	 * @param sourcePr
	 *            source presentation
	 * @param destinPr
	 *            destination presentation
	 * @param graphPresentation 
	 * @param graphSelection 
	 */
	public AddEdgeCommand(VertexPresentation sourcePr, VertexPresentation destinPr, GraphPresentation graphPresentation, GraphElementSelection graphSelection) {
		this.graphSelection = graphSelection;
		this.graphPresentation = graphPresentation;
		edge = new EdgePresentation(sourcePr, destinPr, graphPresentation.isDirected(), graphPresentation.isWeighted());
	}

	public void execute() {
		graphSelection.unselect();
		graphPresentation.addEdge(edge);
		graphSelection.selectEdge(edge);
	}

	public void undo() {
		graphSelection.unselect();
		graphPresentation.removeEdge(edge);
	}

}